/**
 * The SelectionTool allows a user to select Shapes in the Drawing.
 * It currently only allows pointing and clicking,
 * but it could be improved to allow rubber-banding
 * (dragging up a rubber-band rectangle to select all enclosed Shapes).
 * 
 * Also, we could extend the SelectionTool to allow dragging shapes
 * to move them to a new position.
 * 
 * @author Gregory Banfi (gregory.banfi@usi.ch);
 */

package ch.usi.inf.pf2.gui;

import java.awt.event.MouseEvent;

import ch.usi.inf.pf2.Component;
import ch.usi.inf.pf2.puts.Input;

public final class SelectionTool extends Tool {

	private Component selectedComponent;


	public SelectionTool(final Model model) {
		super(model, "Select", "cursor.png");
	}

	/**
	 * This methods responds when the selection tool is clicked. In the case it
	 * finds the component on which the user clicked, then prints a message on
	 * the console and add the component to the selection. If the Shift key is
	 * pressed the user can select more object at the same time.
	 */
	@Override
	public void mouseClicked(final MouseEvent ev) {
		final int x = ev.getX();
		final int y = ev.getY();
		selectedComponent = getDrawing().findComponentAt(x, y);
		System.out.println("mouseClicked on " + selectedComponent);
		if (!ev.isShiftDown()) {
			getSelection().clear();
		}
		if (selectedComponent != null) {
			getSelection().add(selectedComponent);
		}
		if(selectedComponent instanceof Input) {
			Drawing.getInputs().clear();
			Drawing.getInputs().add((Input) selectedComponent);
			System.out.println("added   "+selectedComponent+ "  to inputs");
		}
	}
}

	